package com.zhangfb95.crosschain.server.timer;

import com.zhangfb95.crosschain.server.service.CrossChainService;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 跨链定时器
 *
 * @author zhangfubing
 * @since 2023/10/20
 */
@Slf4j
@Component
public class CrossChainTimer {

    @Autowired
    private CrossChainService crossChainService;

    @PostConstruct
    public void init() {
        initSyncTimer();
    }

    /**
     * 同步定时器
     */
    private void initSyncTimer() {
        Thread syncThread = new Thread(() -> {
            while (true) {
                try {
                    crossChainService.syncChainInfos();
                    Thread.sleep(3000L);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
        });
        syncThread.start();
    }
}
